package com.js.controller;

import com.js.entity.DAdmin;
import com.js.service.DAdminService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;

/**
 * (DAdmin)表控制层
 *
 * @author makejava
 * @since 2022-06-15 14:03:42
 */
@RestController
@RequestMapping("dAdmin")
@CrossOrigin
@Slf4j
public class DAdminController {
    /**
     * 服务对象
     */
    @Resource
    private DAdminService dAdminService;

    /**
     * 分页查询
     *
     * @param dAdmin 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<DAdmin>> queryByPage(DAdmin dAdmin, PageRequest pageRequest) {
        return ResponseEntity.ok(this.dAdminService.queryByPage(dAdmin, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<DAdmin> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.dAdminService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param dAdmin 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<DAdmin> add(@RequestBody DAdmin dAdmin) {
        Date date = new Date();
        log.info("对 DAdmin 的操作<===>添加<===>此时时间为{}",date);
        return ResponseEntity.ok(this.dAdminService.insert(dAdmin));
    }

    /**
     * 编辑数据
     *
     * @param dAdmin 实体
     * @return 编辑结果
     */
    @PostMapping("/update")
    public void update(@RequestBody DAdmin  dAdmin ){
        Date date = new Date();
        log.info("对 DAdmin 的操作<===>修改<===>此时时间为{}",date);
        this.dAdminService.update(dAdmin);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        Date date = new Date();
        log.info("对 DAdmin 的操作<===>删除<===>此时时间为{}",date);
        return ResponseEntity.ok(this.dAdminService.deleteById(id));
    }
      /**
     * 查询所有 数据
     *
     * 
     * @return List 
     */
     @GetMapping("/query")
     public List<DAdmin> queryAll(){
         Date date = new Date();
        log.info("对 DAdmin 的操作<===>查询全部<===>此时时间为{}",date);
        List<DAdmin>  dAdmin=this.dAdminService.queryAll();
        return dAdmin ;
     }

}

